//
//  BaseSKScene.m
//  shandong_porker
//
//  Created by Developer on 2025-01-08.
//  Copyright © 2025 ShandongPoker. All rights reserved.
//

#import "BaseSKScene.h"

@interface BaseSKScene ()

@property (nonatomic, assign, readwrite) BOOL isSetupComplete;

@end

@implementation BaseSKScene

#pragma mark - Lifecycle

- (void)didMoveToView:(SKView *)view {
    [super didMoveToView:view];
    
    if (!self.isSetupComplete) {
        [self setupScene];
        [self bindViewModel];
        self.isSetupComplete = YES;
    }
}

#pragma mark - Setup Methods

- (void)setupScene {
    // 子类重写此方法
}

- (void)bindViewModel {
    // 子类重写此方法
}

- (void)updateWithViewModel {
    // 子类重写此方法
}

#pragma mark - Scene Control

- (void)pauseScene {
    self.paused = YES;
}

- (void)resumeScene {
    self.paused = NO;
}

#pragma mark - Animation Helpers

- (void)addFadeInAnimationToNode:(SKNode *)node duration:(NSTimeInterval)duration {
    node.alpha = 0.0;
    SKAction *fadeIn = [SKAction fadeInWithDuration:duration];
    [node runAction:fadeIn];
}

- (void)addSlideInAnimationToNode:(SKNode *)node 
                        direction:(CGVector)direction 
                         duration:(NSTimeInterval)duration {
    CGPoint originalPosition = node.position;
    node.position = CGPointMake(originalPosition.x + direction.dx, 
                               originalPosition.y + direction.dy);
    
    SKAction *slideIn = [SKAction moveTo:originalPosition duration:duration];
    slideIn.timingMode = SKActionTimingEaseOut;
    [node runAction:slideIn];
}

@end